<template>
  <div class="account">
      <iframe class="orderIframe" ref="iframe" :src="ifarmeSrc" frameborder="0" width="100%" scrolling="no" id="bdIframe" style="height:100vh"></iframe>
  </div>
</template>
<script>
import {findByEpId} from '@/api/stock'
export default {
  data(){
      return{
          ifarmeSrc:'',
          companyList:[],
      }
  },
  created(){
      this.ifarmeSrc = process.env.VUE_APP_BASE_URL_WINNER_URL + 'order/list';
  },
  methods:{
    async handercompany(){
      let date = await findByEpId();
      console.log(date,'44444444444res');
      if( date.success){
        this.companyList = date.result;
        let oIframeDom = document.getElementById('bdIframe');
        // 父页面向子页面传参
        let data = {
            type: 'supplier',
            code:200,
            companyList:this.companyList,
        };
        console.log(data,'image.pngimage.png');
        oIframeDom.onload = () => {
            console.log("parent onload");
            document.getElementById("bdIframe").contentWindow.postMessage(data, '*');
        };
      }else{
        this.$message.error(date.message)
      }
    },
    handleMessage(event){
        const {data} = event
        console.log(data,'--------------------------');
        if(data.type === 'orderChild'){
           console.log(data.data,'子传父数据');
          //  let orderObj = JSON.stringify(data.data);
           this.$router.push({name:'OrderDetail'})
        }    
    },
    initIframe(){
      // let oIframeDom = document.getElementById('bdIframe');
      // const deviceHeight = document.documentElement.clientHeight;
      // oIframeDom.style.height = (Number(deviceHeight)-120) + 'px';
    },

  },
  mounted(){
    this.handercompany();
    this.initIframe();
    // 接收子页面传来的数据
    window.addEventListener('message',this.handleMessage);
    let that = this;
    window.onresize = function(){
      that.initIframe();
    }  
  },
  watch:{
  },
  destroyed(){
    window.removeEventListener('message',this.handleMessage);
  },

}
</script>
<style scoped>
  .account{
      width: 100%;
      height: auto;
  }
  .orderIframe{
    width: 100%;
    height: 100%;
    
  }
</style>